/*
 * Thread.h
 *
 *  Created on: 2021年4月5日
 *      Author: san
 */

#ifndef BASE_THREAD_H_
#define BASE_THREAD_H_

#include <pthread.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <functional>
#include <memory>
#include <string>
#include "CountDownLatch.h"
#include "noncopyable.h"

namespace san {

class Thread : noncopyable {
public:
	typedef std::function<void ()> ThreadFunc;
	explicit Thread(const ThreadFunc &, const std::string &name = std::string());
	~Thread();

	void start();
	int join();
	bool started() const { return started_; }


private:
	void setDefaultName();
	bool started_;
	bool joined_;
	pthread_t pthreadId_;
	pid_t tid_;
	ThreadFunc threadFunc_;
	std::string name_;
	CountDownLatch latch_;
};

} /* namespace san */

#endif /* BASE_THREAD_H_ */
